Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: TCP src port is unset on the TCP DNS response flow #5078

Merged
merged 1 commit into from
Jun 9, 2023

Conversation

wenyingd
Copy link
Contributor

@wenyingd wenyingd commented Jun 5, 2023

This change is to resolve an issue in ANP with FQDN rules which has sent all TCP packets marked with ack and psh flags to antrea-agent rather than only sent the DNS response packets.

The root cause is the existing code would add a match pair with tp_dst=0 into the service match pairs even if no dst port is set in the ANP prtocols. Then the DNS logic has picked a wrong service match pair to generate the OpenFlow entries.

This change directly generates the conjunctive match conditions for DNS response packets rather than calling getServiceMatchPairs to make the logic simply.

tcpServiceMatch := &conjunctiveMatch{
tableID: conj.serviceClause.ruleTable.GetID(),
matchPairs: []matchPair{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding the root cause of this issue.
I think you can simply fix it by changing matchPairs here to matchPairs: append(dnsTCPMatchPair, tcpFlagsMatchPair),
Before adding source port support, dnsTCPMatchPair only has one item inside. Now, for a service with a source port match, getServiceMatchPairs will generate two pairs. One is for the destination port, matching port 0(match all) and the other is for the source port, matching the port we provided.
cc @Dyanngg since he is the owner of source port support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The truth is we only care about TCP source port and TCP flags, why it is a must to add a match for dst port value 0 although it does not work on OVS?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, from my understanding, that part could be improved. Let's see @Dyanngg 's opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we could refine the logic for matchPairs. We do not have to add the match for dst port if src port matching is the only "filter" we have on the traffic. The code is written in the current way simply because dst port matching is a much common case and I wanted to simplify the implementation (instead of explicitly covering cases for src port matching only, dst port matching only and src dst port matching).

@luolanzone luolanzone linked an issue Jun 7, 2023 that may be closed by this pull request
@luolanzone luolanzone added action/backport Indicates a PR that requires backports. action/release-note Indicates a PR that should be included in release notes. labels Jun 7, 2023
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

pkg/agent/openflow/network_policy.go Outdated Show resolved Hide resolved
} else {
klog.InfoS("Invalid protocol for TCP DNS", "protocol", proto)
continue
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have assumed there will only be IP and IPv6 in other places anyway, no need to add an unreachable branch

conjActionFlow := func(proto binding.Protocol) binding.Flow {
ctZone := CtZone
if proto == binding.ProtocolIPv6 {
ctZone = CtZoneV6
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, removed "else" branch.

@@ -1416,3 +1417,70 @@ func Test_featureNetworkPolicy_initFlows(t *testing.T) {
})
}
}

func Test_NewDNSPacketInConjunction(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great test. I assume it will fail without the patch, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is failed before the change.

This change is to resolve an issue in ANP with FQDN rules which has sent all TCP
packets marked with ack and psh flags to antrea-agent rather than only sent the
DNS response packets.

The root cause is the existing code would add a match pair with tp_dst=0 into
the service match pairs even if no dst port is set in the ANP prtocols. Then
the DNS logic has picked a wrong service match pair to generate the OpenFlow
entries.

This change directly generates the conjunctive match conditions for DNS response
packets rather than calling `getServiceMatchPairs` to make the logic simply.

Signed-off-by: wenyingd <wenyingd@vmware.com>
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tnqn
Copy link
Member

tnqn commented Jun 8, 2023

This change directly generates the conjunctive match conditions for DNS response packets rather than calling getServiceMatchPairs to make the logic simply. It also resolves the bug in function getServiceMatchPairs

@wenyingd the desription mentioned it resolves bug in function getServiceMatchPairs, which I don't find. Is it still accurate?

@wenyingd
Copy link
Contributor Author

wenyingd commented Jun 8, 2023

This change directly generates the conjunctive match conditions for DNS response packets rather than calling getServiceMatchPairs to make the logic simply. It also resolves the bug in function getServiceMatchPairs

@wenyingd the desription mentioned it resolves bug in function getServiceMatchPairs, which I don't find. Is it still accurate?

No, I removed that part out from this change, but forgot to change the commit message.
Removed the sentence.

@tnqn
Copy link
Member

tnqn commented Jun 8, 2023

/test-ipv6-e2e
/test-ipv6-only-e2e

@tnqn
Copy link
Member

tnqn commented Jun 8, 2023

@Dyanngg @GraysonWu please let us know if you have other comments.

Copy link
Contributor

@GraysonWu GraysonWu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tnqn
Copy link
Member

tnqn commented Jun 9, 2023

/skip-conformance
/skip-networkpolicy

@wenyingd
Copy link
Contributor Author

wenyingd commented Jun 9, 2023

/test-vm-e2e

@tnqn tnqn merged commit 7f02a63 into antrea-io:main Jun 9, 2023
@tnqn
Copy link
Member

tnqn commented Jun 9, 2023

@wenyingd please backport it to release-1.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/backport Indicates a PR that requires backports. action/release-note Indicates a PR that should be included in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ANP with FQDN rules does not work correctly on TCP traffic
5 participants